@echo off
setlocal enabledelayedexpansion

rd /s /q ProtoBuf\generate\
mkdir ProtoBuf\generate\
mkdir ProtoBuf\generate\csharp\

REM ------------------------------------------------------------------------------------------
echo --- Performing pre-process cleanup... ---

cd ProtoBuf\ProtoGen\
del /q *.proto 
cd ..\..

cd ProtoBuf\ProtoFile\
del /q *.proto 
cd ..\..

REM ------------------------------------------------------------------------------------------
echo --- Copying all .proto files into \ProtoBuf\ProtoGen\ and \ProtoBuf\ProtoFile\ ---

cd ProtoFile

for /f "tokens=* delims= " %%a in ('dir /b *.proto') do (
echo copying %%~a
copy %%~a ..\ProtoBuf\ProtoGen\%%~a
copy %%~a ..\ProtoBuf\ProtoFile\%%~a
)

cd ..

REM ------------------------------------------------------------------------------------------
echo --- calling protogen.exe for all copied .proto files ---

cd ProtoBuf\ProtoGen\

set in_files=
set in_files_tmp1=-i:
for /f "tokens=* delims= " %%a in ('dir /b *.proto') do (
set "in_files= %in_files_tmp1%%%~a !in_files! "
)
echo %in_files%

protogen.exe %in_files% -o:../generate/csharp/PBMessage.cs -ns:ProtoBuf.Message


cd ..\..

echo Begin generate OpCode

REM ------------------------------------------------------------------------------------------
echo --- calling PBGenerator.exe for all copied .proto files ---

cd ProtoBuf\ProtoGen\

set proto_files=

for /f "tokens=* delims= " %%a in ('dir /b *.proto') do (
set "proto_files=!proto_files! %%~a"
)

cd ..

PBGenerator.exe %proto_files% protobuf.message ProtoBuf.Message

pause